package com.wxw.gulidemo.handler;/**
 * @author by xxz
 * @date 2022/5/26
 */

import com.wxw.gulidemo.R;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description         全局异常处理器

 * @author by xxz

 * @date 2022/5/26

 * @throws
 */
@Component
@ControllerAdvice  //必要
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)  //指定异常类型
    @ResponseBody    //需要加@ResponeseBody返回数据
    public R exceptionHandler(Exception ex){
        ex.printStackTrace();
        return R.error().message("——全局异常处理——");
    }
}
